package com.czl.module_service.adapter.inventory

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.InventoryAssetBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemInventoryChildAssetBinding
import com.czl.module_service.fragment.inventory.InventoryChildFragment

/**
 * @author by xubin
 * PS: Not easy to write code, please indicate.
 */
class InventoryChildAdapter(private val fragment: InventoryChildFragment) :
    BaseQuickAdapter<InventoryAssetBean, BaseDataBindingHolder<ItemInventoryChildAssetBinding>>(
        R.layout.item_inventory_child_asset
    ) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemInventoryChildAssetBinding>,
        item: InventoryAssetBean
    ) {
        if (item.isCheck == 2) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.icn_panying)
        }
        if (item.isCheck == 3) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.icn_publicshenqing_x)
        }
        if (item.isCheck != null && item.isCheck == 0 || item.isCheck != null && item.status == 0) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.oval_green)
        }
        if (item.isCheck != null && item.isCheck == 1 && item.isReplace == 0) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.icn_publicshenqing_gou)
        }
        /*if (item.isReplace != null && item.isReplace == 0) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.icn_pd_daipan)
        }*/
        if (item.isReplace != null && item.isReplace == 1) {
            holder.getView<ImageView>(R.id.iv_asset).setImageResource(R.mipmap.icn_pd_daipan)
        }
        item.position = holder.layoutPosition - 1
        if (item.imgList?.size!! > 0) {
            item.imgUrl = item.imgList!![0].imgUrl
        }
        holder.dataBinding?.run {
            data = item
            adapter = this@InventoryChildAdapter
            executePendingBindings()
        }
        holder.dataBinding?.tetete?.setOnClickListener(object : View.OnClickListener {
            override fun onClick(p0: View?) {
                if (p0 != null) {
                    fragment.showMenu(item, p0)
                }
//                substitute()
            }
        })

    }

    val onImageClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is InventoryAssetBean) {
            val bundle = Bundle()
            bundle.putString(AppConstants.BundleKey.SHOW_BIG_IMG, it.imgUrl)
            fragment.startContainerActivity(
                AppConstants.Router.Service.F_SERVICE_SHOW_BIG_IMG,
                bundle
            )
        }
    })

}